package com.nuoniu.sibanyun.controller.crm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmShareConfig;
import com.nuoniu.sibanyun.service.crm.ICrmShareConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 分享管理 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-09-22
 */
@RestController
@RequestMapping("/crm/shareConfig")
@Api(tags = "分享管理")
public class CrmShareConfigController extends BaseController {

    @Autowired
    private ICrmShareConfigService shareConfigService;

    /**
     * 获取分享列表
     * @author 小啊刚
     * @date 2021-09-23
     */
    @ApiOperation("获取分享列表")
    @GetMapping("getList")
    public HttpResult getList(Integer status) {
        return HttpResult.ok(shareConfigService.getList(status));
    }

    @ApiOperation("保存分享")
    @PostMapping("save")
    public HttpResult save(@RequestBody CrmShareConfig shareConfig) {
        if(shareConfig == null) {
            throw new NuoNiuException("数据不能为空");
        }

        shareConfigService.saveShare(shareConfig);
        return HttpResult.ok();
    }

    @ApiOperation("删除分享")
    @DeleteMapping("delete")
    public HttpResult delete(Integer id) {
        shareConfigService.removeById(id);
        return HttpResult.ok();
    }

    @ApiOperation("统计次数")
    @GetMapping("countShare")
    public HttpResult countShare(Integer id) {
        shareConfigService.countShare(id);
        return HttpResult.ok();
    }
}
